<?php
namespace app\common\validate;

/**
 * 验证器：管理员
 * @package app\common\validate
 * @author jwj <jwjbjg@gmail.com>
 * @copyright jwj
 */
class Administrator extends Validate
{
    // 验证规则
    protected $rule = [
        'id'         => ['require'],
        'captcha'    => ['require', 'captcha' => 'login'],
        'username'   => ['require', 'unique:administrator', 'max' => 32],
        'password'   => ['require', 'max' => 18],
    ];

    // 字段信息
    protected $field = [
        'id'         => 'ID',
        'captcha'    => '验证码',
        'username'   => '用户名',
        'password'   => '密码',
    ];

    /**
     * 场景：添加管理员
     * @return \app\common\validate\Administrator
     */
    public function sceneAdd()
    {
        return $this->remove('id', true);
    }

    /**
     * 场景：编辑管理员
     * @return \app\common\validate\Administrator
     */
    public function sceneEdit(){
        return $this->remove('password', ['require']);
    }

    /**
     * 场景：修改我的资料
     * @return \app\common\validate\Administrator
     */
    public function sceneProfile()
    {
        return $this->only(['username', 'password'])
            ->remove('password', ['require']);
    }

    /**
     * 场景：登录
     * @return \app\common\validate\Administrator
     */
    public function sceneLogin()
    {
        return $this->only(['username', 'password', 'captcha'])
            ->remove('username', ['unique']);
    }
}